<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="divport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        #app{
            display: grid;
            align-items: center;
            justify-items: center;
            grid-template-columns: repeat(3,1fr);
            grid-row-gap: 20px;
        }
        .item{
            width: 17.5695vw;
        }
        .pic{
            width: 14.6413vw;
            height: 19.7657vw;
        }
        .pf{
            display: flex;
        }
        .pf img{
            width: 2.1962vw;
            height: 2.1962vw;
        }
        .fen{
        display: inline;
        }
    </style>
</head>
<body>
    <div id="app">
        <div v-for="item of movie" :key="item.id" class="item">
            <img :src="item.pic" alt="" class="pic">
            <p class="name">{{item.title}}</p>

              <div class="pf">
                
                <div v-for="value of transfromStar(item.raiting)">
                  <img v-if="value>=1.5" src="images/star.png"></img>
                  <img v-else-if="value>=1" src="images/ban-star.png"></img>
                  <img v-else src="images/no-star.png"></img>
                </div>
                <p class="fen">{{item.raiting}}</p>
              </div>
              
        </div>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                movie:[],
                arr:"",
            },
            mounted(){
                $.ajax({
                    url:"http://192.168.4.84:8000/top250"
                }).then(res=>{
                    this.movie=res.result 
                })
                
            },
            methods:{
                handleTitle(value){
                    if (value.length > 6) {
                        return value.slice(0, 6) + "..."
                    }
                    return value;
                },
                transfromStar(num){
                    let arr = [];
                    for(let i=0;i<5;i++){
                    if(num>2){
                        arr.push(2)
                    }else if(num>0){
                        arr.push(Number(num.toFixed(1)))
                    }else{
                        arr.push(0)
                    }
                    num=num-2;
                    }
                    return arr;
                }
            }
        })
    </script>
</body>
</html>